home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / news / inn1.000 / inn1.4sec-linux-src.tar / inn / samples / tally.unwanted < prev    next >
Text File  |  1993-03-18  |  1KB  |  59 lines

  1. #!/bin/sh
  2. ##  $Revision: 1.4 $
  3. ##  Tally/update the unwanted newsgroup log
  4. ##  Read an innd log on stdin, scan it for articles that were unwanted
  5. ##  because they newsgroups were not in our active file.  Update unwanted.log
  6. ##  to have the new count of unwanted groups, and how often they were used.
  7.  
  8. ##  =()<. @<_PATH_SHELLVARS>@>()=
  9. . /news/lib/innshellvars
  10.  
  11. PROGNAME=unwanted
  12. LOCK=${LOCKS}/LOCK.${PROGNAME}
  13. LOG=${MOST_LOGS}/unwanted.log
  14.  
  15. UNWANTED_NEW=${LOG}.new
  16. UNWANTED_OLD=${LOG}.old
  17.  
  18. ##  Lock.
  19. shlock -f ${LOCK} -p $$ || {
  20.     echo "$0: cannot lock $LOCK" 1>&2
  21.     exit 2
  22. }
  23.  
  24. ##  Prepare the files.
  25. if [ ! -f ${LOG} ]; then
  26.     touch ${LOG}
  27.     chmod 0660 ${LOG}
  28. fi
  29. rm -f ${UNWANTED_NEW} ${UNWANTED_OLD}
  30. ln ${LOG} ${UNWANTED_OLD}
  31. touch ${UNWANTED_NEW}
  32. chmod 0660 ${UNWANTED_NEW}
  33.  
  34. ##  Grab the data.
  35. ${AWK} '$4 == "-" && $7 == "437" && $8 == "Unwanted" { print }' \
  36.     | ${SED} 's/.*"\(.*\)".*/\1/' \
  37.     | sort \
  38.     | uniq -c \
  39.     | cat - ${LOG} \
  40.     | ${AWK} 'BEGIN {
  41.         unwanted[0]=0;
  42.     }
  43.     {
  44.         unwanted[$2] += $1;
  45.     }
  46.     END {
  47.         for (group in unwanted) {
  48.         if (group != 0) {
  49.             print unwanted[group], group;
  50.         }
  51.         }
  52.     }' \
  53.     | sort -n -r >${UNWANTED_NEW}
  54. mv -f ${UNWANTED_NEW} ${LOG}
  55.  
  56. ##  All done.
  57. rm -f ${LOCK}
  58. exit 0
  59.